<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <template id="sub-component">
        <div>
            <h2>我是子组件</h2>
            <p>姓名：{{name}}</p>
            <p>年龄：{{age}}</p>
            <h3>列表</h3>
            <ol>
                <li v-for="item in list">{{item}}</li>
            </ol>
        </div>
    </template>
    <main id="app">
        <sub-component name="奉先" age="35"></sub-component>
        <sub-component :name="name" :age="age"></sub-component>
        <sub-component/>
    </main>
</body>
<script src="../../vue.js"></script>
<script>
    Vue.component("sub-component", {
        template: "#sub-component",
        props: {
            name: {
                type: String,
                default: "匿名"
            },
            age: {
                type: Number,
                default: 0
            },
            list: {
                type: Array,
                default: () => {
                    return ["你","我","他"]
                }
            }
        }
    })

    new Vue({
        el: "#app",
        data() {
            return {
                name: "Hydra",
                age: 18
            }
        }
    })
</script>

</html>